package com.shr25.robot.qq.controller;

import com.shr25.robot.qq.model.Vo.QqPluginVo;
import com.shr25.robot.qq.service.RobotManagerService;
import com.shr25.robot.qq.util.MessageUtil;
import lombok.extern.slf4j.Slf4j;
import net.mamoe.mirai.contact.ContactList;
import net.mamoe.mirai.contact.Group;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @date 2022/6/28 20:00
 */
@Slf4j
@RequestMapping("bot")
@RestController
public class BotController {
    @Autowired
    private RobotManagerService robotManagerService;

    /**
     * 插件列表
     * @return
     */
    @GetMapping(value = "allGroup")
    public Object allGroup() {
        ContactList<Group> groups = MessageUtil.getAllGroups();
        //将list转map 【key为1个属性,value为1个属性】
        Map<Long, Long> data = groups.stream().collect(Collectors.toMap(
                group ->  group.getId(),
                group -> group.getBot().getId(),
                (key, val) -> key));  //（map的键重复不会报错，下面已经处理）
        Map rs = new HashMap();
        rs.put("code", "200");
        rs.put("data", data);
        return rs;
    }

    /**
     * 插件列表
     * @return
     */
    @GetMapping(value = "initGroupBot")
    public Object list() {
        ContactList<Group> groups = MessageUtil.getAllGroups();
        //将list转map 【key为1个属性,value为1个属性】
        Map<Long, Long> data = groups.stream().collect(Collectors.toMap(
                group ->  group.getId(),
                group -> group.getBot().getId(),
                (key, val) -> key));  //（map的键重复不会报错，下面已经处理）
        Map rs = new HashMap();
        rs.put("code", "200");
        rs.put("data", data);
        return rs;
    }
}
